package com.zhp.dao.impl;

import com.zhp.dao.CommentDao;
import com.zhp.pojo.HComment;
import com.zhp.utils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @date 2023/4/12
 * @desc
 */
public class CommentDaoImpl implements CommentDao {

    QueryRunner queryRunner = new QueryRunner(DbUtils.getDataSource());

    @Override
    public List<HComment> findCommentByDid(String did) {

        String sql="SELECT * FROM h_comment h JOIN h_order o ON h.oid = o.oid  \n" +
                " JOIN h_userinfo u ON o.edid=u.did WHERE did = ?";

        List<HComment> query = null;
        try {
            query = queryRunner.query(sql, new BeanListHandler<>(HComment.class), did);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return query;
    }
}
